﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Data.SqlClient;
using System.Configuration;
using Delonix_Regia_Hotel.Class;

namespace Delonix_Regia_Hotel.Class
{
    public class Staff
    {
        private string staffid;
        private string firstname;
        private string lastname;
        private int ic;
        private int age;
        private string dob;
        private int contact;
        private string address;
        private string email;
        private int bank_num;

        public Staff()
        {
        }
        public Staff(string staffid, string firstname, string lastname, int ic, int age, string dob, int contact, string address, string email, int bank_num)
        {
            this.staffid = staffid;
            this.firstname = firstname;
            this.lastname = lastname;
            this.ic = ic;
            this.age = age;
            this.dob = dob;
            this.contact = contact;
            this.address = address;
            this.email = email;
            this.bank_num = bank_num;
        }

        public string Staffid
        {
            get { return staffid; }
            set { staffid = value; }

        }

        public string Firstname
        {
            get { return firstname; }
            set { firstname = value; }
        }
        public string Lastname
        {
            get { return lastname; }
            set { lastname = value; }
        }
        public int Ic
        {
            get { return ic; }
            set { ic = value; }
        }
        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        public string Dob
        {
            get { return dob; }
            set { dob = value; }
        }
        public int Contact
        {
            get { return contact; }
            set { contact = value; }
        }
        public string Address
        {
            get { return address; }
            set { address = value; }
        }
        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        public int Bank_num
        {
            get { return bank_num; }
            set { bank_num = value; }
        }

        public static int CreateStaff(Staff u)
        {
            int rowsinserted = 0;
            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = " Data source =.;Initial Catalog = Delonix; Integrated Security = true";
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = " INSERT INTO STAFF(staffid,firstname,lastname,ic,age,dob,contact,address,email,bank_num)"
                 + " VALUES(@staffid,@fname,@lname,@ic,@age,@dob,@dob,@contact,@address,@email,@bank_num)";
                comm.Parameters.AddWithValue("@staffid", u.staffid);
                comm.Parameters.AddWithValue("@fname", u.firstname);
                comm.Parameters.AddWithValue("@lname", u.lastname);
                comm.Parameters.AddWithValue("@ic", u.ic);
                comm.Parameters.AddWithValue("@age", u.age);
                comm.Parameters.AddWithValue("@dob", u.dob);
                comm.Parameters.AddWithValue("@contact", u.contact);
                comm.Parameters.AddWithValue("@address", u.address);
                comm.Parameters.AddWithValue("@email", u.email);
                comm.Parameters.AddWithValue("@bank_num", u.bank_num);

                rowsinserted = comm.ExecuteNonQuery();
            }

            catch (SqlException e)
            {
                throw e;
            }

            conn.Close();
            return rowsinserted;
        }




        public static int UpdateStaff(Staff m)
        {
            int rowsupdated = 0;
            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DelonixConnectionString"].ConnectionString;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "UPDATE STAFF SET staffid=@staffid,fname=@fname,lname=@lname,ic=@ic,age=@age,dob=@dob,contact=@contact,address=@address,email=@email,bank_num=@bank_num";
                comm.Parameters.AddWithValue("@fname", m.firstname);
                comm.Parameters.AddWithValue("@lname", m.lastname);
                comm.Parameters.AddWithValue("@ic", m.ic);
                comm.Parameters.AddWithValue("@age", m.age);
                comm.Parameters.AddWithValue("@dob", m.dob);
                comm.Parameters.AddWithValue("@contact", m.contact);
                comm.Parameters.AddWithValue("@address", m.address);
                comm.Parameters.AddWithValue("@email", m.email);
                comm.Parameters.AddWithValue("@bank_num", m.bank_num);

                rowsupdated = comm.ExecuteNonQuery();
            }
            catch (SqlException e)
            {
                throw e;
            }
            conn.Close();
            return rowsupdated;
        }
        public static int DeleteStaffbyid(string staffid)
        {
            int rowsdeleted = 0;

            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DelonixConnectionString"].ConnectionString;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "DELETE FROM Staff WHERE staffid=@staffid";

                comm.Parameters.AddWithValue("@staffid", staffid);

                rowsdeleted = comm.ExecuteNonQuery();
            }
            catch (SqlException e)
            {
                throw e;
            }
            conn.Close();
            return rowsdeleted;
        }


    }
}